<?php
//
// +------------------------------------------------------------------------+
// | Gecko Framework                                                        |
// +------------------------------------------------------------------------+
//
require_once("Gecko/Form/Exception.php");
require_once("Gecko/Form/Field.php");
require_once("Zend/Registry.php" );
require_once("Gecko/Router.php" );

/**
 * Color Selector with Javascript picker
 *
 * @package Gecko.Form.Field;
 * @author Christopher Valderrama <valderrama.christopher@gmail.com>
 * @copyright Copyright (c) 2008
 * @version $Id$v1.0$ 2008
 * @access public
 **/
class Gecko_Form_Field_ColorPicker extends Gecko_Form_Field {
	/**
	 * Controls if the Div was included (color picker div)
	 *
	 * @var boolean
	 */
	private static $divIncluded = false;

	/**
	 * Controls if the Javascript code was included
	 *
	 * @var boolean
	 */
	private static $JSIncluded = false;

	/**
	 * Control type
	 *
	 * @var string
	 */
	protected $type = 'color';

	/**
	 * Returns the HTML Control
	 */
	public function getControl() {
		$params = $this->getParams();
		$value = $this->getValue();
		$name = $this->getName();
		$vars = array();
		$template = Gecko_Router::LIBRARY_DIR . "/Assets/Form/Templates/Color.php";
		$scriptDir = Gecko_Router::ASSETS_DIR . "/JavaScriptHelpers/";

		$btnId = $name . "_colorPickButton";
		$watchId = $name . "_watchColor";
		$html = '';
		if(!self::$divIncluded) {
			$html = '<div id="colorpicker201" class="colorpicker201"></div>';
			self::$divIncluded = true;
		}
		$vars['watchId'] = $watchId;
		$vars['btnId'] = $btnId;
		$vars['size'] = "9";
		$vars['name'] = $name;
		$vars['value'] = $value;
		$vars['rawName'] = $name;
		$vars['colorDir'] = $scriptDir;
		$vars['html'] = $html;
		$vars['inRouter'] = Zend_Registry::isRegistered("base");
		$vars['JSIncluded'] = self::$JSIncluded;

		$html = Gecko_Template::renderTemplate( $template, $vars, true );

		if( !self::$JSIncluded ) {
			self::$JSIncluded = true;
		}

		return $html;
	}
}